﻿using Microsoft.AspNetCore.Mvc;
using seejee_Backendium.Core.Interfaces;
using seejee_Backendium.Core.Models;
using seejee_Backendium.Data.Services;

namespace seejee_Backendium.WEB.Controllers
{
    [ApiController]
    [Route("api/[controller]")] // 路由：api/Acc
    public class UserInfoController : ControllerBase
    {
        private readonly ILogger<UserInfoController> _logger;
        private readonly IUserInfoService _userInfoService;

        // 构造函数修复：正确赋值_logger
        public UserInfoController(ILogger<UserInfoController> logger, IUserInfoService userInfoService)
        {
            _logger = logger;
            _userInfoService = userInfoService;
        }
        [HttpGet("all")] // 路由：api/Acc/all
        public async Task<ActionResult<IEnumerable<UserReginfo>>> GetAllAccList()
        {
            try
            {
                var result = await _userInfoService.GetAllAsync();
                return Ok(result); // 无论空/非空，均返回200+数据（空集合也比404更合理）
            }
            catch (Exception ex)
            {
                _logger.LogError(ex, "获取所有数据源记录失败");
                return StatusCode(500, "服务器内部错误：获取数据失败");
            }
        }



        [HttpGet("get")] // 路由：api/Acc/all
        public async Task<ActionResult<IEnumerable<UserinfoForGet>>> GetList()
        {
            try
            {
                var result = await _userInfoService.GetCusForGetAsync();
                return Ok(result); // 无论空/非空，均返回200+数据（空集合也比404更合理）
            }
            catch (Exception ex)
            {
                _logger.LogError(ex, "获取所有数据源记录失败");
                return StatusCode(500, "服务器内部错误：获取数据失败");
            }
        }
    }
}
